/**
 * File Comment: Ita a GUI
 */
package edu.gatech.oad.project.presentation;
//$codepro.audit.disable
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;

import edu.gatech.oad.project.networking.clientSessions.AdminSessionClient;

/**
 * This class is a panel that allows the user
 * to interact with the GUI to view a list
 * of existing users in the system.
 * 
 * @author Group 17
 * @version 1
 */
public class UserList extends JPanel {
  
  /**
   * Field driver: holds the Driver connected to the GUI
   */
  private Driver driver;
  
  /**
   * Field list: list of current users in the system
   */
  public JList list;
  
  /**
   * Field list_1: list of pending requests
   */
  public JList list_1;
  
  /**
   * Field textField: set password field
   */
 private JTextField textField;
 
 /**
  * Field btnEditUser: edit user button
  */
 public JButton btnEditUser;
 
 /**
  * Field btnRemoveUser: remove user button
  */
 public JButton btnRemoveUser;
 
 /**
  * Field btnAddUser: create user button
  */
 public JButton btnAddUser;
 
 /**
  * Field btnBackToHome: back button
  */
 public JButton btnBackToHome;
 
 /**
  * Field password account password
  */
 private String password;

 /**
  * Constructor.
  * 
  * @param driver the Driver connected to the GUI
  */
 public UserList(Driver driver) {
   this.driver = driver;
   List<String> userList = ((AdminSessionClient) this.driver.getSession()).getAllUsersInSystem();
   //parse by stringname.split(" ")
   List<String> pendingList = ((AdminSessionClient) this.driver.getSession()).getInactiveUsersInSystem();
   //parse by stringname.split(" ")
   
  GridBagLayout gridBagLayout = new GridBagLayout();
  gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
  gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  gridBagLayout.columnWeights = new double[]{0.0, 1.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
  gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  setLayout(gridBagLayout);
  
  JLabel lblUsersInSystem = new JLabel("Users in System");
  lblUsersInSystem.setFont(new Font("Lucida Grande", Font.PLAIN, 30));
  GridBagConstraints gbc_lblUsersInSystem = new GridBagConstraints();
  gbc_lblUsersInSystem.gridwidth = 5;
  gbc_lblUsersInSystem.insets = new Insets(0, 0, 5, 0);
  gbc_lblUsersInSystem.gridx = 0;
  gbc_lblUsersInSystem.gridy = 0;
  add(lblUsersInSystem, gbc_lblUsersInSystem);
  
  JLabel lblCurrentUsers = new JLabel("Current Users");
  GridBagConstraints gbc_lblCurrentUsers = new GridBagConstraints();
  gbc_lblCurrentUsers.insets = new Insets(0, 0, 5, 5);
  gbc_lblCurrentUsers.gridx = 0;
  gbc_lblCurrentUsers.gridy = 1;
  add(lblCurrentUsers, gbc_lblCurrentUsers);
  
  // work on list
  list = new JList();
  GridBagConstraints gbc_list = new GridBagConstraints();
  gbc_list.gridheight = 2;
  gbc_list.gridwidth = 3;
  gbc_list.insets = new Insets(0, 0, 5, 5);
  gbc_list.fill = GridBagConstraints.BOTH;
  gbc_list.gridx = 1;
  gbc_list.gridy = 1;
  add(list, gbc_list);
  
  btnEditUser = new JButton("Edit User");
  btnEditUser.addActionListener(new ButtonListener1(this));
  GridBagConstraints gbc_btnEditUser = new GridBagConstraints();
  gbc_btnEditUser.insets = new Insets(0, 0, 5, 5);
  gbc_btnEditUser.gridx = 1;
  gbc_btnEditUser.gridy = 3;
  add(btnEditUser, gbc_btnEditUser);
  
  btnRemoveUser = new JButton("Remove User");
  btnRemoveUser.addActionListener(new ButtonListener2(this));
  GridBagConstraints gbc_btnRemoveUser = new GridBagConstraints();
  gbc_btnRemoveUser.insets = new Insets(0, 0, 5, 5);
  gbc_btnRemoveUser.gridx = 3;
  gbc_btnRemoveUser.gridy = 3;
  add(btnRemoveUser, gbc_btnRemoveUser);
  
  JLabel lblPendingRequests = new JLabel("Pending Requests");
  GridBagConstraints gbc_lblPendingRequests = new GridBagConstraints();
  gbc_lblPendingRequests.insets = new Insets(0, 0, 5, 5);
  gbc_lblPendingRequests.gridx = 0;
  gbc_lblPendingRequests.gridy = 4;
  add(lblPendingRequests, gbc_lblPendingRequests);
  
  //work on list
  list_1 = new JList();
  GridBagConstraints gbc_list_1 = new GridBagConstraints();
  gbc_list_1.gridheight = 2;
  gbc_list_1.gridwidth = 3;
  gbc_list_1.insets = new Insets(0, 0, 5, 5);
  gbc_list_1.fill = GridBagConstraints.BOTH;
  gbc_list_1.gridx = 1;
  gbc_list_1.gridy = 4;
  add(list_1, gbc_list_1);
  
  JLabel lblSetPassword = new JLabel("Set Password");
  GridBagConstraints gbc_lblSetPassword = new GridBagConstraints();
  gbc_lblSetPassword.insets = new Insets(0, 0, 5, 5);
  gbc_lblSetPassword.gridx = 1;
  gbc_lblSetPassword.gridy = 6;
  add(lblSetPassword, gbc_lblSetPassword);
  
  textField = new JTextField();
  textField.addCaretListener(new CaretListener() {
    public void caretUpdate(CaretEvent e) {
      password = textField.getText();
    }
  });
  GridBagConstraints gbc_textField = new GridBagConstraints();
  gbc_textField.gridwidth = 2;
  gbc_textField.insets = new Insets(0, 0, 5, 5);
  gbc_textField.fill = GridBagConstraints.HORIZONTAL;
  gbc_textField.gridx = 2;
  gbc_textField.gridy = 6;
  add(textField, gbc_textField);
  textField.setColumns(10);
  
  btnAddUser = new JButton("Create User");
  btnAddUser.addActionListener(new ButtonListener3(this));
  GridBagConstraints gbc_btnAddUser = new GridBagConstraints();
  gbc_btnAddUser.insets = new Insets(0, 0, 0, 5);
  gbc_btnAddUser.gridx = 1;
  gbc_btnAddUser.gridy = 7;
  add(btnAddUser, gbc_btnAddUser);
  
  btnBackToHome = new JButton("Back to Home");
  btnBackToHome.addActionListener(new ButtonListener4(this));
  GridBagConstraints gbc_btnBackToHome = new GridBagConstraints();
  gbc_btnBackToHome.insets = new Insets(0, 0, 0, 5);
  gbc_btnBackToHome.gridx = 3;
  gbc_btnBackToHome.gridy = 7;
  add(btnBackToHome, gbc_btnBackToHome);
 } // end constructor method

 /**
  * Get the Driver.
  * 
  * @return the Driver connected to the GUI
  */
 public Driver getDriver()
 {
   return this.driver;
 } // end getDriver method
 
 /**
  * This private inner class implements ActionListener for btnEditUser.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener1 implements ActionListener
 {
   /**
    * Field ul: the UserList being used
    */
   private UserList ul;
   
   /**
    * Field driver: holds the driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param ul the UserList being used
    */
   private ButtonListener1(UserList ul)
   {
     this.ul = ul;
     this.driver = ul.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     //Edit User information
     this.ul.btnEditUser.setText("User edited");
   } // end actionPerformed method
 } // end ButtonListener1 class
 
 /**
  * This private inner class implements ActionListener for btnRemoveUser.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener2 implements ActionListener
 {
   /**
    * Field ul: the UserList being used
    */
   private UserList ul;
   
   /**
    * Field driver: holds the driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param ul the UserList being used
    */
   private ButtonListener2(UserList ul)
   {
     this.ul = ul;
     this.driver = ul.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     //call removeUser in SystemAdmin class
     this.ul.btnRemoveUser.setText("User removed");
   } // end actionPerformed method
 } // end ButtonListener2 class
 
 /**
  * This private inner class implements ActionListener for btnAddUser.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener3 implements ActionListener
 {
   /**
    * Field ul: the UserList being used
    */
   private UserList ul;
   
   /**
    * Field driver: holds the driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param ul the UserList being used
    */
   private ButtonListener3(UserList ul)
   {
     this.ul = ul;
     this.driver = ul.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     // this.driver.getSession().activateUser(this.ul.getSelectedPending())
     this.ul.btnAddUser.setText("User now active");
   } // end actionPerformed method
 } // end ButtonListener3 class
 
 /**
  * This private inner class implements ActionListener for btnBackToHome.
  * 
  * @author Group 17
  * @version 1
  */
 private class ButtonListener4 implements ActionListener
 {
   /**
    * Field ul: the UserList being used
    */
   private UserList ul;
   
   /**
    * Field driver: holds the driver connected to the GUI
    */
   private Driver driver;
   
   /**
    * Constructor.
    * 
    * @param ul the UserList being used
    */
   private ButtonListener4(UserList ul)
   {
     this.ul = ul;
     this.driver = ul.getDriver();
   } // end constructor method
   
   /**
    * Default method for ActionListener.
    * 
    * @param e the ActionEvent triggering the ActionListener
    */
   public void actionPerformed(ActionEvent e)
   {
     this.driver.getFrame().setContentPane(new SysAdminHome(this.driver));
     this.driver.getFrame().pack();
   } // end actionPerformed method
 } // end ButtonListener4 class
} // end UserList class